 using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Configuration;
using System.Drawing;
using System.Threading;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using eBay.Service.Call;
using eBay.Service.Core.Sdk;
using eBay.Service.Core.Soap;
using eBay.Service.Util;

namespace NewebayAPI
{
    public class pullData()
     {
      
        public void Catagorys()
        {
            LstCategories.Items.Clear();

                GetCategoriesCall apicall = new GetCategoriesCall(apiContext);
                apicall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll);

                apicall.EnableCompression = this.chkcomp.Checked;

                // Set ebat detail to pull all catagorys
                apicall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll);
                CategoryTypeCollection cats = apicall.GetCategories();

                foreach (CategoryType category in cats)
                {
                    string[] listparams = new string[8];
                    listparams[0] = category.CategoryID;
                    listparams[1] = category.CategoryLevel.ToString();
                    listparams[2] = category.CategoryName;
                    listparams[3] = category.CategoryParentID[0].ToString();
                    listparams[4] = category.LeafCategory.ToString();
                    listparams[5] = category.BestOfferEnabled.ToString();
                    listparams[6] = apicall.ApiResponse.MinimumReservePrice.ToString();

                    ListViewItem vi = new ListViewItem(listparams);
                    this.LstCategories.Items.Add(vi);


          
      
      
        }
      
      
     };
    public class Form1 : Form
    {
        private static ApiContext apiContext = null;

        public Form1()
        {
            InitializeComponent();
        }

        private GroupBox groupBox1;
        private Label label8;
        private Label label7;
        private Label label6;
        private Label label5;
        private Label label4;
        private Label label3;
        private Label label2;
        private Label label1;
        private TableLayoutPanel tableLayoutPanel1;
        private TextBox txtUsrID;
        private TextBox txtEIAS;
        private TextBox txtStarColor;
        private TextBox txtFeedBk;
        private TextBox txtNeg;
        private TextBox txtNeu;
        private TextBox txtPos;
        private TextBox textBox8;
        private Button button1;
        private Button button2;
        private GroupBox GrpResult;
        private Label LblCategories;
        private ListView LstCategories;
        private ColumnHeader ClmCatId;
        private ColumnHeader ClmLevel;
        private ColumnHeader ClmName;
        private ColumnHeader ClmParent;
        private ColumnHeader ClmLeaf;
        private ColumnHeader ClmBestOfferEnabled;
        private ColumnHeader ClmMinimumReservePrice;
        private Label lblthread;
        private CheckBox chkcomp;


        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.lblthread = new System.Windows.Forms.Label();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
            this.label1 = new System.Windows.Forms.Label();
            this.label8 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label7 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.txtUsrID = new System.Windows.Forms.TextBox();
            this.txtEIAS = new System.Windows.Forms.TextBox();
            this.txtStarColor = new System.Windows.Forms.TextBox();
            this.txtFeedBk = new System.Windows.Forms.TextBox();
            this.txtNeg = new System.Windows.Forms.TextBox();
            this.txtNeu = new System.Windows.Forms.TextBox();
            this.txtPos = new System.Windows.Forms.TextBox();
            this.textBox8 = new System.Windows.Forms.TextBox();
            this.GrpResult = new System.Windows.Forms.GroupBox();
            this.LblCategories = new System.Windows.Forms.Label();
            this.LstCategories = new System.Windows.Forms.ListView();
            this.ClmCatId = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.ClmLevel = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.ClmName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.ClmParent = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.ClmLeaf = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.ClmBestOfferEnabled = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.ClmMinimumReservePrice = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.chkcomp = new System.Windows.Forms.CheckBox();
            this.groupBox1.SuspendLayout();
            this.tableLayoutPanel1.SuspendLayout();
            this.GrpResult.SuspendLayout();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.chkcomp);
            this.groupBox1.Controls.Add(this.lblthread);
            this.groupBox1.Controls.Add(this.button1);
            this.groupBox1.Controls.Add(this.button2);
            this.groupBox1.Controls.Add(this.tableLayoutPanel1);
            this.groupBox1.Location = new System.Drawing.Point(12, 64);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(559, 428);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "groupBox1";
            // 
            // lblthread
            // 
            this.lblthread.AutoSize = true;
            this.lblthread.Location = new System.Drawing.Point(93, 48);
            this.lblthread.Name = "lblthread";
            this.lblthread.Size = new System.Drawing.Size(104, 13);
            this.lblthread.TabIndex = 10;
            this.lblthread.Text = "Thread Not Running";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(355, 389);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 9;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(464, 389);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 1;
            this.button2.Text = "button2";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // tableLayoutPanel1
            // 
            this.tableLayoutPanel1.ColumnCount = 2;
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 32.01133F));
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 67.98867F));
            this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0);
            this.tableLayoutPanel1.Controls.Add(this.label8, 0, 7);
            this.tableLayoutPanel1.Controls.Add(this.label2, 0, 1);
            this.tableLayoutPanel1.Controls.Add(this.label7, 0, 6);
            this.tableLayoutPanel1.Controls.Add(this.label3, 0, 2);
            this.tableLayoutPanel1.Controls.Add(this.label6, 0, 5);
            this.tableLayoutPanel1.Controls.Add(this.label4, 0, 3);
            this.tableLayoutPanel1.Controls.Add(this.label5, 0, 4);
            this.tableLayoutPanel1.Controls.Add(this.txtUsrID, 1, 0);
            this.tableLayoutPanel1.Controls.Add(this.txtEIAS, 1, 1);
            this.tableLayoutPanel1.Controls.Add(this.txtStarColor, 1, 2);
            this.tableLayoutPanel1.Controls.Add(this.txtFeedBk, 1, 3);
            this.tableLayoutPanel1.Controls.Add(this.txtNeg, 1, 4);
            this.tableLayoutPanel1.Controls.Add(this.txtNeu, 1, 5);
            this.tableLayoutPanel1.Controls.Add(this.txtPos, 1, 6);
            this.tableLayoutPanel1.Controls.Add(this.textBox8, 1, 7);
            this.tableLayoutPanel1.Location = new System.Drawing.Point(7, 99);
            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
            this.tableLayoutPanel1.RowCount = 8;
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 45.83333F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 54.16667F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 33F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 33F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 37F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 40F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 38F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 32F));
            this.tableLayoutPanel1.Size = new System.Drawing.Size(353, 283);
            this.tableLayoutPanel1.TabIndex = 8;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(3, 0);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(43, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "UserID:";
            // 
            // label8
            // 
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(3, 250);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(35, 13);
            this.label8.TabIndex = 7;
            this.label8.Text = "label8";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(3, 32);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(78, 13);
            this.label2.TabIndex = 1;
            this.label2.Text = "EIAS Token is:";
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(3, 212);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(98, 26);
            this.label7.TabIndex = 6;
            this.label7.Text = "Total count of Positive Feedback:";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(3, 69);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(89, 13);
            this.label3.TabIndex = 2;
            this.label3.Text = "Rating Star color:";
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(3, 172);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(95, 26);
            this.label6.TabIndex = 5;
            this.label6.Text = "Total count of Neutral Feedback:";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(3, 102);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(87, 13);
            this.label4.TabIndex = 3;
            this.label4.Text = "Feedback score:";
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(3, 135);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(104, 26);
            this.label5.TabIndex = 4;
            this.label5.Text = "Total count of Negative Feedback:";
            // 
            // txtUsrID
            // 
            this.txtUsrID.Location = new System.Drawing.Point(115, 3);
            this.txtUsrID.Name = "txtUsrID";
            this.txtUsrID.ReadOnly = true;
            this.txtUsrID.Size = new System.Drawing.Size(100, 20);
            this.txtUsrID.TabIndex = 8;
            // 
            // txtEIAS
            // 
            this.txtEIAS.Location = new System.Drawing.Point(115, 35);
            this.txtEIAS.Name = "txtEIAS";
            this.txtEIAS.ReadOnly = true;
            this.txtEIAS.Size = new System.Drawing.Size(100, 20);
            this.txtEIAS.TabIndex = 9;
            // 
            // txtStarColor
            // 
            this.txtStarColor.Location = new System.Drawing.Point(115, 72);
            this.txtStarColor.Name = "txtStarColor";
            this.txtStarColor.ReadOnly = true;
            this.txtStarColor.Size = new System.Drawing.Size(100, 20);
            this.txtStarColor.TabIndex = 10;
            // 
            // txtFeedBk
            // 
            this.txtFeedBk.Location = new System.Drawing.Point(115, 105);
            this.txtFeedBk.Name = "txtFeedBk";
            this.txtFeedBk.ReadOnly = true;
            this.txtFeedBk.Size = new System.Drawing.Size(100, 20);
            this.txtFeedBk.TabIndex = 11;
            // 
            // txtNeg
            // 
            this.txtNeg.Location = new System.Drawing.Point(115, 138);
            this.txtNeg.Name = "txtNeg";
            this.txtNeg.ReadOnly = true;
            this.txtNeg.Size = new System.Drawing.Size(100, 20);
            this.txtNeg.TabIndex = 12;
            // 
            // txtNeu
            // 
            this.txtNeu.Location = new System.Drawing.Point(115, 175);
            this.txtNeu.Name = "txtNeu";
            this.txtNeu.ReadOnly = true;
            this.txtNeu.Size = new System.Drawing.Size(100, 20);
            this.txtNeu.TabIndex = 13;
            // 
            // txtPos
            // 
            this.txtPos.Location = new System.Drawing.Point(115, 215);
            this.txtPos.Name = "txtPos";
            this.txtPos.ReadOnly = true;
            this.txtPos.Size = new System.Drawing.Size(100, 20);
            this.txtPos.TabIndex = 14;
            // 
            // textBox8
            // 
            this.textBox8.Location = new System.Drawing.Point(115, 253);
            this.textBox8.Name = "textBox8";
            this.textBox8.Size = new System.Drawing.Size(100, 20);
            this.textBox8.TabIndex = 15;
            // 
            // GrpResult
            // 
            this.GrpResult.Controls.Add(this.LblCategories);
            this.GrpResult.Controls.Add(this.LstCategories);
            this.GrpResult.Location = new System.Drawing.Point(19, 507);
            this.GrpResult.Name = "GrpResult";
            this.GrpResult.Size = new System.Drawing.Size(760, 280);
            this.GrpResult.TabIndex = 11;
            this.GrpResult.TabStop = false;
            this.GrpResult.Text = "Result";
            // 
            // LblCategories
            // 
            this.LblCategories.Location = new System.Drawing.Point(16, 24);
            this.LblCategories.Name = "LblCategories";
            this.LblCategories.Size = new System.Drawing.Size(475, 23);
            this.LblCategories.TabIndex = 12;
            this.LblCategories.Text = "Categories:";
            // 
            // LstCategories
            // 
            this.LstCategories.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.ClmCatId,
            this.ClmLevel,
            this.ClmName,
            this.ClmParent,
            this.ClmLeaf,
            this.ClmBestOfferEnabled,
            this.ClmMinimumReservePrice});
            this.LstCategories.GridLines = true;
            this.LstCategories.Location = new System.Drawing.Point(24, 48);
            this.LstCategories.Name = "LstCategories";
            this.LstCategories.Size = new System.Drawing.Size(720, 208);
            this.LstCategories.TabIndex = 13;
            this.LstCategories.UseCompatibleStateImageBehavior = false;
            this.LstCategories.View = System.Windows.Forms.View.Details;
            // 
            // ClmCatId
            // 
            this.ClmCatId.Text = "Category Id";
            this.ClmCatId.Width = 83;
            // 
            // ClmLevel
            // 
            this.ClmLevel.Text = "Level";
            this.ClmLevel.Width = 40;
            // 
            // ClmName
            // 
            this.ClmName.Text = "Name";
            this.ClmName.Width = 150;
            // 
            // ClmParent
            // 
            this.ClmParent.Text = "Parent Id";
            // 
            // ClmLeaf
            // 
            this.ClmLeaf.Text = "Leaf";
            this.ClmLeaf.Width = 40;
            // 
            // ClmBestOfferEnabled
            // 
            this.ClmBestOfferEnabled.Text = "BestOfferEnabled";
            this.ClmBestOfferEnabled.Width = 100;
            // 
            // ClmMinimumReservePrice
            // 
            this.ClmMinimumReservePrice.Text = "MinimumReservePrice";
            this.ClmMinimumReservePrice.Width = 120;
            // 
            // chkcomp
            // 
            this.chkcomp.AutoSize = true;
            this.chkcomp.Location = new System.Drawing.Point(310, 48);
            this.chkcomp.Name = "chkcomp";
            this.chkcomp.Size = new System.Drawing.Size(148, 17);
            this.chkcomp.TabIndex = 11;
            this.chkcomp.Text = "Enable HTTP compresion";
            this.chkcomp.UseVisualStyleBackColor = true;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(1162, 897);
            this.Controls.Add(this.GrpResult);
            this.Controls.Add(this.groupBox1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.tableLayoutPanel1.ResumeLayout(false);
            this.tableLayoutPanel1.PerformLayout();
            this.GrpResult.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion
        [STAThread]
       public static int Main()
        {
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Form1 oForm1 = new Form1();

            
            
            //Thread oThread = new Thread(new ThreadStart(oForm1.GetUsr));
            
            pullData tPullData = new pullData();
            Thread oThread = new Thread(new ThreadStart(tPullData.Catagorys));
            Application.Run(new Form1());
        }
        static ApiContext GetApiContext()
        {
            if (apiContext != null)
            {
                return apiContext;
            }
            else
            {
                apiContext = new ApiContext();
                apiContext.SoapApiServerUrl = ConfigurationManager.AppSettings["Environment.ApiServerUrlSB"];
                
                //Set api token to access ebay api server
                ApiCredential apiCredential = new ApiCredential();
                apiCredential.eBayToken = ConfigurationManager.AppSettings["UserAccount.ApiToken"];
                apiContext.ApiCredential = apiCredential;
                apiContext.Site = SiteCodeType.US;


                //API Logging
                apiContext.ApiLogManager = new ApiLogManager();
                apiContext.ApiLogManager.ApiLoggerList.Add(
                    new FileLogger(ConfigurationManager.AppSettings["LogFileName"], true, true, true));
                apiContext.ApiLogManager.EnableLogging = true;

                

                return apiContext;
            }
        }
        private void Form1_load(object sender, EventArgs e)
        {
            ApiContext apiContext = GetApiContext();

        }

        //Request userData from ebay
        public void GetUsr()
        {
            try
            {
                txtUsrID.Text = "";
                txtStarColor.Text = "";
                txtPos.Text = "";
                txtNeu.Text = "";
                txtNeg.Text = "";
                txtFeedBk.Text = "";
                txtEIAS.Text = "";


                GetUserCall apiCall = new GetUserCall(apiContext);

                apiCall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll);

                UserType user = apiCall.GetUser();
                //apiCall.Execute();
                txtUsrID.Text = user.UserID;
                txtStarColor.Text = user.FeedbackRatingStar.ToString();
                txtPos.Text = user.UniquePositiveFeedbackCount.ToString();
                txtNeu.Text = user.UniqueNeutralFeedbackCount.ToString();
                txtNeg.Text = user.UniqueNegativeFeedbackCount.ToString();
                txtEIAS.Text = user.EIASToken.ToString();
                txtFeedBk.Text = user.FeedbackScore.ToString();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }

        }

        public void GetCats()
        {
            
            try
            {
                                }
                {
                    
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        // Get user Button
        private void button1_Click(object sender, EventArgs e)
        {
           // ThreadTest tt = new ThreadTest(); // Create a common instance
            //new Thread(tt.Go).Start();
            //tt.Go();


            Form1 t = new Form1();
            new Thread(t.GetUsr).Start();
            t.Go();
           
            
        }
            void Go()
            {
                lblthread.Text = t.IsAlive ? "Thread is now RUNNING" : "Thread is Dead";
            }
        private void button2_Click(object sender, EventArgs e)
        {
        
          oThread.start();
        }

        
    }
}
